package com.xxx.management.web.controller;


import com.xxx.management.web.util.R;
import com.xxx.user.api.MenuApi;
import com.xxx.user.dto.MenuCreateReqDTO;
import com.xxx.user.dto.MenuGetAllResDTO;
import com.xxx.user.dto.MenuUpdateReqDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@AllArgsConstructor
public class MenuController {

    private final MenuApi menuApi;

    /**
     * 创建菜单
     */
    @PostMapping("/v1/menu/create")
    public R<String> create(@RequestBody MenuCreateReqDTO param) {
        return R.ok(menuApi.create(param));
    }

    /**
     * 更新菜单
     */
    @PutMapping("/v1/menu/update")
    public R<String> update(@RequestBody MenuUpdateReqDTO param) {
        return R.ok(menuApi.update(param));
    }

    /**
     * 删除菜单
     */
    @DeleteMapping("/v1/menu/delete")
    public R<String> delete(@RequestBody List<Long> ids) {
        return R.ok(menuApi.delete(ids));
    }

    /**
     * 获取菜单
     */
    @GetMapping("/v1/menu/getAll")
    public R<List<MenuGetAllResDTO>> getAll() {
        return R.ok(menuApi.getAll());
    }

    /**
     * 刷新菜单权限缓存
     */
    @PostMapping("/v1/menu/refreshMenuCache")
    public R<Boolean> refreshMenuCache(@RequestBody List<Long> menuIds) {
        return R.ok(menuApi.refreshMenuCache(menuIds));
    }

}
